<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ include file="/common/taglibs.jsp"%>
<html>
  <head>
    <base href="<%=basePath%>">
    <title>My JSP 'userList.jsp' starting page</title>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<script type="text/javascript" >
		   var result = "${result}";
  		   if(result=='1'){
  		 	  alert("保存成功！");
  		      document.location.href ='${ctx}/pages/user/list.action';
  		   }
  		   
  		   function subForm(){
		   		var userName = $("#userName").val();
		   		var password = $("#password").val();
		   		var realName = $("#realName").val();
		   		if(!checkUser || checkIsNull(userName)){
		   			alert("请按要求输入账号");
		   			$("#userName").focus();
		   			return false;
		   		}else if(checkIsNull(password)){
		   			alert("密码不能为空");
		   			$("#password").focus();
		   			return false;
		   		}else if(checkIsNull(realName)){
		   			alert("真是名称不能为空");
		   			$("#realName").focus();
		   			return false;
		   		}
		   		$("#userForm").submit();
		   }
		   
				var checkUser = false;
				function checkAccount(){
					var userName = $("#userName").val();
					if($.trim(userName).length<1){
						checkUser = false;
     		 			$("#userNameError").addClass("error");
     		 			$("#userNameError").html("用户名不能为空");
     		 			$("#userNameError").removeClass("success");
     		 			return ;
					}
					
					//if($.trim(userName).length<5){
					//	checkUser = false;
     		 		//	$("#userNameError").addClass("error");
     		 		//	$("#userNameError").html("账号长度必须5位以上");
     		 		//	$("#userNameError").removeClass("success");
     		 		//	return ;
					//}
					
					$.ajax({ 
					    type: "POST",
						url: "${ctx}/pages/user/checkAccount.action",
						data:{'userName':userName},
						dataType:"text",
						success: function(data){
		     		 		if(data==1){
		     		 			$("#userNameError").addClass("success");
		     		 			$("#userNameError").html("");
		     		 			$("#userNameError").removeClass("error");
		     		 			checkUser = true;
		     		 		}else{
		     		 			checkUser = false;
		     		 			$("#userNameError").addClass("error");
		     		 			$("#userNameError").html("用户名已经存在");
		     		 			$("#userNameError").removeClass("success");
		     		 		}
		     		 	}
	     		 	});
				}
		</script>
  </head>
  
  <body>
  <div id="body-wrapper">
		<div id="main-content">
			<div class="content-box">
				<!-- Start Content Box -->
				<div class="content-box-header">
					<h3 style="cursor: s-resize;">
						添加用户
					</h3>
					<div class="clear"></div>
				</div>
				<!-- End .content-box-header -->
				<div style="display: block;" class="content-box-content">
					<form method="post" id="userForm" name="userForm" action="${ctx }/pages/user/save.action"
						>
						<fieldset>
							<!-- Set class to "column-left" or "column-right" on fieldsets to divide the form into columns -->
							<p>
								<label>
									用户名
								</label>
								<input id="userName" onblur="checkAccount()" class="text-input small-input"
									name="user.userName" type="text">
								<span id="userNameError" class="input-notification png_bg"></span>
							<p>
								<label>
									密码
								</label>
								<input  class="text-input small-input"
									name="user.loginPwd" id="password" type="password">
							</p>
							<p>
								<label>
									真实姓名
								</label>
								<input  class="text-input small-input"
									name="user.realName" id="realName" type="text">
							</p>
							<p>
								<label>
									手机号
								</label>
								<input  class="text-input small-input"
									name="user.phone" id="phone" type="text">
							</p>
							<p>
								<label>
									状态
								</label>
								<select class="small-input" name="user.status">
									<option value="1">
										启用
									</option>
									<option value="0">
										锁定
									</option>
								</select>
							</p>
							<p>
								<label>
									备注
								</label>
								<textarea class="text-input textarea " id="textarea"
									name="user.remark" rows="8"></textarea>
							</p>
							<p>
								<label>
									用户角色
								</label>
								
								<c:forEach  items="${roleList}" var="role">
									<input type="checkbox" value="${role.id}" name="userRoleCB">${role.name} &nbsp;&nbsp;&nbsp;&nbsp;
								</c:forEach>

							</p>
							<p>
								<input class="button" value="提交" onclick="subForm();"  type="button">
								<input class="button" value="返回" onclick="history.back();"  type="button">
							</p>
						</fieldset>
						<div class="clear"></div>
						<!-- End .clear -->
					</form>
				</div>
			</div>
		</div>
		</div>
  </body>
</html>
